﻿using System;
using System.Diagnostics;
using Microsoft.FxCop.Sdk;

namespace Community.StaticAnalysis.Design.Rules
{
    internal static class RulesHelper
    {
        /// <summary>
        /// Nodes the has attribute.
        /// </summary>
        /// <param name="node">The node.</param>
        /// <param name="attributeFullName">Full name of the attribute.</param>
        /// <returns></returns>
        public static Boolean NodeHasAttribute(Member node, String attributeFullName)
        {
            Debug.Assert(node != null);

            // Check if the member has not attributes
            if (node.Attributes == null || node.Attributes.Count == 0)
            {
                // No attributes are assigned to the member
                return false;
            }

            // Loop through each attribute on the member
            foreach (AttributeNode item in node.Attributes)
            {
                // Check if the type of the attribute is the attribute full name that we are looking for
                if (item.Type.FullName == attributeFullName)
                {
                    // The member is marked with the attribute being searched for
                    return true;
                }
            }

            // The attribute was not found on the member
            return false;
        }
    }
}